from selenium import webdriver
from time import sleep
import threading


# 封装百度
def open_BaiDu(driver):
    driver.get('https://www.baidu.com')
    sleep(1)
    driver.find_element_by_id("kw").send_keys("自动化")
    sleep(1)
    driver.find_element_by_id("su").click()
    sleep(1)
    driver.quit()


# 封装driver
def get_driver(browser):
    # 定义空变量
    cap = None
    if browser == 'chrome':
        cap = webdriver.DesiredCapabilities.CHROME.copy()
    elif browser == 'firefox':
        cap = webdriver.DesiredCapabilities.FIREFOX.copy()
    # 修改默认平台名称
    cap['platform'] = 'MAC'
    return webdriver.Remote('http://10.5.9.191:18888/wd/hub', cap)


# 遍历多线程


# 定义浏览器列表
broserName = ['chrome', 'firefox']
# 遍历浏览器列表
for broser in broserName:
    driver = get_driver(broser)
    threading.Thread(target=open_BaiDu, args=(driver,)).start()
